﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Model
{
    public class QuestionReplyConfig : IEntityTypeConfiguration<QuestionReply>
    {
        public void Configure(EntityTypeBuilder<QuestionReply> entity)
        {
            entity.ToTable("T_QuestionReply");
            entity.HasKey(qr => qr.Id);  // 设置主键

            entity.Property(qr => qr.Reply).HasMaxLength(2000)  // 回复内容
                .IsRequired();

            entity.Property(qr => qr.QuestionId)  // 问题ID
                .IsRequired();

            entity.Property(qr => qr.StudentId); // 回复学生ID

            entity.Property(qr => qr.TeacherId); // 教师ID
            entity.Property(qr => qr.CreateTime);

            entity.HasOne(qr => qr.Question)  // 问题信息
                .WithMany(q => q.QuestionReplyList)
                .HasForeignKey(qr => qr.QuestionId)
                .OnDelete(DeleteBehavior.NoAction);
        }
    }
}
